﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using NLog;


namespace WOMPS
{
    public class EmailSend
    {
        private static Logger logger = LogManager.GetCurrentClassLogger(); 
        public static bool Send(string message)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info("Start Send");
            }
            try
            {
                MailMessage m = new MailMessage();
                foreach (EmailAddress to in Globals.SendTo)
                {
                    m.To.Add(to.Email);
                }
                m.From = new MailAddress(Globals.SentFrom);
                m.Subject = "New Releases on " + Globals.ServerName;
                m.Body = message;
                m.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient(Globals.SMTPServer, Globals.Port);
                //smtp.Credentials = new System.Net.NetworkCredential("dcals", "113099dc");
                smtp.Send(m);
            }
            catch(Exception exc)
            {
                logger.FatalException("Send", exc);
                return false;
            }
            if (logger.IsInfoEnabled)
            {
                logger.Info("End Send");
            }
            return true;
        }
    }
}
